$(function () {
    let form = layui.form
    form.verify({
        nickname: [
            /^[\S]{1,10}$/,
            '昵称的长度为1-10个字符!'
        ]
    })

    let layer = layui.layer

    initUserinfo()

    function initUserinfo() {
        axios({
            url: '/my/userinfo',
        }).then(res => {
            console.log(res.data);
            if (res.data.status !== 0) {
                return layer.msg(res.data.message)
            }
            form.val('formUserinfo', res.data.data)
        })
    }

    $('#btnReset').on('click', function (e) {
        e.preventDefault()
        initUserinfo()
    })

    $('form').on('submit', function (e) {
        e.preventDefault()
        axios({
            method: 'POST',
            url: '/my/userinfo',
            data: $(this).serialize()
            // data: form.val('formUserinfo')
        }).then(res => {
            console.log(res);
            if (res.data.status != 0) {
                return layer.msg(res.data.message)
            }
            layer.msg('恭喜您,修改用户信息成功!')
            window.parent.qingQiu()
        })
    })

})